(function()
{
	var formFun = function(options)
	{
		this.id = getRandId();
		this.html = '';
		if (options)
		{
			// 构造函数
			this.options = $.extend({
				'container' : '',
				// required 是否表示未有效，调试时可以为false
				'requiredValid' : !config.debug,
				// 提交的url，一般不同的服务有不同的url默认key不填写
				'url' : '',
				// 提交的接口
				'method' : '',
				// 是否显示每行的注释
				'showmemo' : true,
				// 容器 classname
				'classname' : '',
				// 预处理函数，如果错误直接返回错误消息，或返回null，否则返回整理个的数组 function(data) { ... return data; },
				'preDealDataFun' : null,
				// 调用成功之后的函数 参数： d, ad, msg, code
				'requestBackFun' : null,
				// 失败之后的函数 参数: msg,msg2,code,response
				'failedBackFun' : null,
				// 调用初始值函数，backfun为返回data，k-v数组
				'loadDataFun' : null,
				// 提交按钮标题，为false表示没有按钮
				'submitTitle' : '',
				// 保存数据的标识符，缺省则出错
				'savemark' : '',
				// 确认信息，当不为空时，提交前需要确认，该动作发生在最后确认，如果数据不合格，即不产生询问
				'confirm' : '',
				// 超时时间(ms)
				'timeout' : 0,
				// 任何控件发生值变化的函数
				'changefun' : null,
				// 除了提交按钮之外的其它按钮，格式为 {key:{caption:caption,fun:fun}}
				'submitOtherBtn' : false,
				// 顶部文本
				'tophelphtml' : null,
				// 底部文本
				'bottomhelphtml' : null,
				'paras' : {
					// 提交的字段列表，没有字段为一个对象每个对象都为一个详细定义
					'name123' : {
						// 标题，缺失时与name一致
						'caption' : 'cap',
						// 是否为必填数据：0 不要求，1 必填，2 不能为空
						'required' : true,
						// 该行的输入提示，showmemo 为真时显示
						'memo' : '',
						'issave' : false,
						// 规则正则表达式
						'preg' : '',
						// 违背规则时的错误提示
						'pregmemo' : '',
						// 
						'objectid' : '',
						// 数据格式，目前支持 array , date , datetime, bool 或不填写 , bool时自动转换为yes 或 no
						'dataformat' : 'array',
						// 输入框类型: textarea number date time hidden text password select mulselect btnfun
						'inputtype' : 'date',
						// 高度，只针对 textarea
						'height' : '200px',
						// 宽度，只针对 select
						'width' : '100px',
						// 选择时生成备选值的函数， 返回格式为k-v对数组
						'valuelist' : '',
						'readonly' : false,
						// 回车函数
						'enterfun' : null,
						// 控件发生值变化的函数
						'changefun' : null,
						// 点击函数，主要针对 选项控件，其中v为当前控件的值
						'clickfun' : function(v)
						{
						},
						// 输入框为backfun参数即最终获得的值
						'btnfun' : function(backfun)
						{
							// backfun(123);
						},
						'placeholder' : '输入密码',
						'hidden' : false,
						// 当前控件的类
						'classname' : '',
						// 当前控件组的类
						'foclassname' : '',
						// 初始值
						'value' : '',
					},
				// ....
				}
			}, options);
			app.templete(this);
			// ///////////////
			this._setEvent();
			this._show();
		}
	};
	// 根据html对象取得当前
	formFun.prototype.getThis = function(obj)
	{
		var k = $(obj).parents('.formbox');
		if (k.length > 0)
		{
			return app.templete(k[0].id);
		}
		return null;
	}
	// 初始化对象
	formFun.prototype._setEvent = function()
	{
		// 下面只执行一次
		if (formFun.prototype._)
			return;
		formFun.prototype._ = 1;
		var that = this;
		var oldid = '';
		var v = '';
		$('body').on('keydown', '.formbox .enterfun', function(event)
		{
			var ta = that.getThis(this);
			if (!ta)
				return;
			if (event.keyCode == 13)
			{
				var id = $(this).attr('id');
				if (ta.options.paras[id] && ta.options.paras[id].enterfun && $(this).val())
					ta.options.paras[id].enterfun($(this).val());
			}
		});
		$('body').on('change', '.formbox .input', function(event)
		{
			var ta = that.getThis(this);
			if (!ta)
				return;
			var name = $(this).attr('id');
			if (name && ta && ta.options && ta.options.paras && ta.options.paras[name] && ta.options.paras[name].changefun)
			{
				var changefun = ta.options.paras[name].changefun;
				changefun($(this).val());
			}
			if (name && ta && ta.options && ta.options.changefun)
			{
				var changefun = ta.options.changefun;
				changefun($(this).val(), this);
			}
		});
		$('body').on('change', '.formbox .textarea', function(event)
		{
			var ta = that.getThis(this);
			if (!ta)
				return;
			var name = $(this).attr('id');
			if (name && ta && ta.options && ta.options.paras && ta.options.paras[name] && ta.options.paras[name].changefun)
			{
				var changefun = ta.options.paras[name].changefun;
				changefun($(this).val());
			}
			if (name && ta && ta.options && ta.options.changefun)
			{
				var changefun = ta.options.changefun;
				changefun($(this).val(), this);
			}
		});
		$('body').on('click', '.formbox .submit', function()
		{
			var ta = that.getThis(this);
			if (!ta)
				return;
			if ($(this).hasClass('submitOtherBtn'))
			{
				if (!ta.options.submitOtherBtn)
					return;
				for ( var k in ta.options.submitOtherBtn)
				{
					if ($(this).hasClass('submitOtherBtn_' + k))
					{
						var fun = ta.options.submitOtherBtn[k]['fun'];
						if (fun)
							fun();
						return;
					}
				}
				return;
			}
			ta.submit();
		});
		$('body').on('click', '.formbox .btnfun', function()
		{
			var ta = that.getThis(this);
			if (!ta)
				return;
			var name = $(this).attr('data');
			if (!name)
			{
				var name = $(this).attr('id');
				if (!name)
					return;
			}
			ta.runBtnfun(name);
		});
		$('body').on('click', '.formbox input', function()
		{
			var ta = that.getThis(this);
			if (!ta)
				return;
			var name = $(this).attr('id');
			if (name && ta && ta.options && ta.options.paras && ta.options.paras[name] && ta.options.paras[name].clickfun)
			{
				var clickfun = ta.options.paras[name].clickfun;
				clickfun($(this).val(), this);
			}
		});
	};
	formFun.prototype.runBtnfun = function(name)
	{
		var ta = this;
		var btnfun = ta.options.paras[name].btnfun;
		if (!btnfun)
		{
			app.err('未定义（' + name + '）的选择函数');
			return;
		}
		btnfun(function(value)
		{
			var inp = $('#' + ta.id + ' .input#' + name);
			if (inp.length <= 0)
				return;
			inp.val(value);
			if (ta.options.paras[name].changefun)
			{
				var changefun = ta.options.paras[name].changefun;
				changefun(value, inp[0]);
			}
			if (ta.options.changefun)
			{
				var changefun = ta.options.changefun;
				changefun(value, inp[0]);
			}
		}, $('#' + ta.id + ' .input#' + name).val());
	}
	/**
	 * 显示/隐藏项目,v为设定的值，不指定则不更新
	 */
	formFun.prototype.showInput = function(key, ishide, v)
	{
		var k = $('#' + this.id + ' .form-group #' + key).parents('.form-group');
		if (k.length > 0)
		{
			if (ishide)
				k.hide();
			else
				k.show();
		}
		if (typeof v != 'undefined')
			k.val(v);
	}
	formFun.prototype.setParas = function()
	{
		var ta = this;
		var oldid = '';
		$('#' + ta.id + ' .input').each(function()
		{
			if (this.id)
			{
				if (oldid != this.id)
				{
					if (oldid)
					{
						if (ta.options.paras[oldid])
							ta.options.paras[oldid].value = v;
					}
					oldid = '';
					v = '';
				}
				oldid = this.id;
				if (this.type == 'radio')
				{
					if (this.checked)
						v = $(this).val();
				}
				else if (this.type == 'checkbox')
				{
					if (this.checked)
						v += (v ? ',' : '') + $(this).val();
				}
				else
				{
					v = $(this).val();
				}
				v = (v + ' ').trim();
			}
		});
		if (oldid)
		{
			if (ta.options.paras[oldid])
				ta.options.paras[oldid].value = v;
		}
	}
	formFun.prototype.submit = function(backfun)
	{
		var now = new Date().getTime();
		if (this.submit && now - this.submit.time < 333)
			return;
		this.submit.time = now;
		this.setParas();
		this.doSubmit(backfun);
	}
	// 获取或设置字段值
	formFun.prototype.inputData = function(field, value)
	{
		if (!field)
			field = '';
		if (field && arguments.length > 1)
		{
			$('#' + this.id + ' #' + field).val(value);
			return;
		}
		if (field)
			this.setParas();
		var data = {};
		for ( var name in this.options.paras)
		{
			if (!this.options.paras[name] || this.options.paras[name]['hidden'])
				continue;
			if (field && name != field)
				continue;
			var c = this.options.paras[name];
			if (!this.options.requiredValid)
				c.required = false;
			var v = c.value;
			if (c.required && v === '')
			{
				if (!field)
					errorMsg(app.w('login.msg.requiredField') + ' : ' + c.caption);
				return '';
			}
			if (v && c.preg)
			{
				var preg = c.preg;
				if (typeof preg == 'string')
					preg = eval(preg);
				if (!preg.test(v))
				{
					if (!c.pregmemo)
						c.pregmemo = app.w('login.msg.formatError');
					if (!field)
						showMsg(c.caption + ' : ' + c.pregmemo);
					return '';
				}
			}
			if (c.inputtype == 'date' && v)
			{
				var t = new Date(v);
				if (isNaN(t.getTime()))
				{
					if (!field)
						errorMsg(c.caption + ' : ' + app.w('login.msg.dataFormatError'));
					return '';
				}
				v = Math.round(t.getTime() / 1000 + t.getTimezoneOffset() * 60);
			}
			if (c.dataformat == 'array' && v != '')
			{
				var isv = false;
				try
				{
					var obj = JSON.parse(v);
					if (typeof obj == 'object' && obj)
					{
						isv = true;
						v = obj;
					}
				}
				catch (e)
				{
					isv = false;
				}
				if (!isv)
				{
					if (!field)
						errorMsg(c.caption + ' : ' + app.w('login.msg.dataFormatError'));
					return '';
				}
			}
			if (v && c.issave !== undefined && !field)
			{
				if (!this.options.savemark)
				{
					return app.err('有字段需要保存，需要设置 savemark');
				}
				var k = 'ta_' + this.options.savemark + '_' + name;
				app.setStorage(k, v);
			}
			data[name] = v;
		}
		if (field)
		{
			if (!data[field])
				return '';
			return data[field];
		}
		return data;
	}
	formFun.prototype.doSubmit = function(backfun)
	{
		var data = this.inputData();
		if (data === '')
			return;
		if (this.options.preDealDataFun)
		{
			var data = this.options.preDealDataFun(data);
			if (data === null || data === false || data === undefined)
				return;
			else if (data === true)
			{
				if (this.options.requestBackFun)
					this.options.requestBackFun();
				return;
			}
			if (typeof data === 'string')
			{
				errorMsg(data);
				return;
			}
		}
		if (this.options.confirm)
		{
			var that = this;
			confirm(this.options.confirm, function()
			{
				that.request(data, backfun || that.options.requestBackFun);
			})
		}
		else
			this.request(data, backfun || this.options.requestBackFun);
	}
	// 提交数据
	formFun.prototype.request = function(data, backfun)
	{
		if (!this.options.method)
		{
			app.err('UI程序出错，未定义method，如果确实没有，请在preDealDataFun函数中处理完成，并返回null或true，程序将不会到运行到request函数，从而不是使用method');
			return;
		}
		var kk = $('#' + this.id + ' .box-footer button');
		if (kk.length > 0 && kk.hasClass('btn-info'))
		{
			if (kk.hasClass('submiting'))
				return;
			kk.removeClass('btn-info');
			kk.addClass('submiting');
			ajax.setCompleteFun(function()
			{
				kk.addClass('btn-info');
				kk.removeClass('submiting');
			});
		}
		var that = this;
		ajax.request(this.options.method, data, function(d, ad, msg, code)
		{
			if (backfun)
			{
				backfun(d, ad, msg, code);
			}
		}, this.options.failedBackFun ? function(msg, msg2, code, response)
		{
			that.options.failedBackFun(msg, msg2, code, response);
		} : null, false, false, this.options.timeout);
	}
	// 设置默认值，如果没有容器的需要延后调用
	formFun.prototype.setData = function(data)
	{
		var that = this;
		// 如果容器不在，则不调入数据
		if ($('#' + this.id).length <= 0)
			return '';
		if (!data)
		{
			var defaultv = null;
			for ( var name in this.options.paras)
			{
				var a = this.options.paras[name];
				if (!a)
					continue;
				if (a.value != undefined)
				{
					if (!defaultv)
						defaultv = {};
					defaultv[name] = a.value;
				}
				else
				{
					// 尝试保存数据
					if (this.options.savemark && this.options.paras[name] && this.options.paras[name].issave !== undefined)
					{
						var issave = this.options.paras[name].issave;
						v = app.getStorage('ta_' + this.options.savemark + '_' + name);
						if (issave !== true && !v)
						{
							v = issave;
						}
						if (v)
						{
							if (!defaultv)
								defaultv = {};
							defaultv[name] = v;
						}
					}
				}
			}
			if (defaultv)
			{
				that.setData(defaultv);
			}
			var fun = this.options.loadDataFun;
			if (fun)
			{
				var that = this;
				fun(function(data)
				{
					that.setData(data);
				});
			}
			return;
		}
		if (app.lockScreen())
		{
			app.lockScreen(0, function()
			{
				that.setData(data);
			});
			return;
		}
		// 具体初始化表单
		$('#' + this.id + ' .input').each(function()
		{
			var ta = that.getThis(this);
			if (!ta)
				return;
			var name = this.id;
			var v = data[name];
			if (v == undefined)
			{
				if (ta.options.savemark && ta.options.paras[name] && ta.options.paras[name].issave !== undefined)
				{
					var issave = ta.options.paras[name].issave;
					v = app.getStorage('ta_' + ta.options.savemark + '_' + name);
					if (issave !== true && !v)
					{
						v = issave;
					}
					if (!v)
						return;
				}
				else
					return;
			}
			if (ta.options.paras[name])
			{
				var tt = ta.options.paras[name];
				if (tt.dataformat == 'array')
				{
					if (typeof (v) == 'object')
						v = that.getTextFromArray(v);
					else
					{
						try
						{
							var vi = JSON.parse(v);
							if (vi)
								v = that.getTextFromArray(vi);
						}
						catch (err)
						{
							vi = v;
						}
					}
				}
				else if (tt.dataformat == 'date' && /^\d+$/.test(v))
				{
					v = getDateStr(v, false, false, true);
				}
				else if (tt.dataformat == 'datetime' && /^\d+$/.test(v))
				{
					v = getDateStr(v, true, false, true);
				}
				else if (tt.dataformat == 'bool')
				{
					v = (v == 1 || v == 'yes' || v == '1' || v == 'true' || v == true) ? 'yes' : 'no';
				}
			}
			if (this.type == 'radio')
			{
				var k = $(this).parent().parent().find('i.inp');
				k.removeClass('fa-circle-o');
				k.removeClass('fa-circle');
				if (v == $(this).val())
				{
					this.checked = true;
					k.addClass('fa-circle');
				}
				else
				{
					k.addClass('fa-circle-o');
				}
			}
			else if (this.type == 'checkbox')
			{
				var k = $(this).parent().parent().find('i.inp');
				k.removeClass('fa-square-o');
				k.removeClass('fa-check-square-o');
				if ((',,' + v + ',,').indexOf(',' + $(this).val() + ',') > 0)
				{
					this.checked = true;
					k.addClass('fa-check-square-o');
				}
				else
				{
					k.addClass('fa-square-o');
				}
			}
			else if (this.type == 'date')
			{
				if (/^\d+$/.test(v))
				{
					v = getDateStr(v);
				}
				$(this).val(v);
			}
			else if (v)
			{
				$(this).val(v);
			}
		});
	};
	// 显示代码
	formFun.prototype._show = function()
	{
		var container = this.options.container;
		var t = '<div class="box nav-tabs-custom box-info formbox ' + this.options.classname + '" id="' + this.id + '" ';
		if (container == 'maincontent')
			t += ' style="min-height:' + (app.getMainHeight() - 21) + 'px;margin-top:24px"';
		t += '>';
		if (this.options.tophelphtml)
			t += '<div class="tip tophelphtml">' + this.options.tophelphtml + '</div>';
		t += '<div class="box-body">';
		var dcla = 'col-sm-5';
		var showmemo = this.options.showmemo && !app.m;
		if (!showmemo)
			dcla = 'col-sm-9';
		var justName = '';
		for ( var name in this.options.paras)
		{
			if (this.options.paras[name])
				justName = name;
		}
		if (justName && !this.options.paras[justName].enterfun)
		{
			var itp = this.options.paras[justName].inputtype;
			if (!itp || itp == 'number' || itp == 'text' || itp == 'password')
			{
				var that = this;
				this.options.paras[justName].enterfun = function()
				{
					that.submit();
				};
			}
		}
		for ( var name in this.options.paras)
		{
			var a = this.options.paras[name];
			if (!a || a['hidden'])
				continue;
			var itp = a['inputtype'];
			if (!itp)
				itp = 'text';
			var valuelist = a['valuelist'];
			if (!a['placeholder'])
				a['placeholder'] = '';
			if (!a['classname'])
				var classname = '';
			else
				var classname = ' ' + a['classname'];
			if (!a['foclassname'])
				var foclassname = '';
			else
				var foclassname = ' ' + a['foclassname'];
			var inputbtn = false;
			if (itp == 'btnfun' || (a.btnfun && a['readonly']))
			{
				classname += ' btnfun';
				inputbtn = true;
			}
			if (!a['caption'])
				a['caption'] = '';
			if (!a['memo'])
				a['memo'] = '';
			var readonly = '';
			if (a['readonly'])
				readonly = ' readonly="true" '
			if (itp == 'hidden')
			{
				t += '<input class="input" type="hidden" id="' + name + '">';
				continue;
			}
			t += '<div class="form-group fo-' + name + foclassname + '">';
			t += '<label class="col-sm-2 control-label">' + a['caption'];
			if (a['required'])
				t += ' <i class="required">*</i> ';
			t += '</label>';
			t += '<div class="' + dcla + '">';
			if (itp == 'date' || itp == 'time')
			{
				t += '<div class="input-group date"><div class="input-group-addon">' + getIC('calendar') + '</div>';
				t += '<input ' + readonly + ' type="' + itp + '" class="form-control pull-right input ' + classname + '" id="' + name + '" data="' + name + '" placeholder="' + a['placeholder'] + '">';
				t += '</div>';
			}
			else if (itp == 'number' || itp == 'text' || itp == 'password')
			{
				if (itp == 'password')
					classname += ' password';
				var re = ' editabled="true" ';
				if (app.needWTPJp())
				{
					re = ' readonly="true" editabled="true" ';
					classname += ' editabled';
				}
				if (a.enterfun)
					classname += ' enterfun';
				t += '<input ' + (a['objectid'] ? (' id="' + a['objectid'] + '" ') : '') + readonly + re + ' class="form-control input ' + classname + '" type="' + itp + '" id="' + name + '" data="' + name + '" placeholder="' + a['placeholder'] + '">';
			}
			else if (itp == 'select' || itp == 'mulselect') // 单选
			{
				var list = [];
				if (valuelist)
					list = valuelist;
				for ( var va in list)
				{
					var w = '';
					if (a['width'])
					{
						var ww = (a['width'] + ' ').trim();
						if (ww.indexOf('px') < 0 && ww.indexOf('%') < 0)
							ww += 'px';
						w = "style='width:" + ww + "'";
					}
					if (readonly)
					{
						if (itp == 'select')
							t += ' <span><span class="hidden"><input class="input" type="radio" name="' + name + '" id="' + name + '" value="' + va + '"></span><label ' + w + ' class="select ' + classname + '">' + getIC('square-o inp') + ' ' + list[va] + '</label></span> ';
						else
							t += ' <span><span class="hidden"><input class="input" type="radio" name="' + name + '" id="' + name + '" value="' + va + '"></span><label ' + w + ' class="select ' + classname + '">' + getIC('circle-o inp') + ' ' + list[va] + '</label></span> ';
					}
					else
					{
						if (itp == 'select')
							t += ' <label ' + w + ' class="select ' + classname + '"><input class="input" type="radio" name="' + name + '" id="' + name + '" value="' + va + '"> ' + list[va] + '</label> ';
						else
							t += ' <label ' + w + ' class="select ' + classname + '"><input class="input" type="checkbox" name="' + name + '" id="' + name + '" value="' + va + '"> ' + list[va] + '</label> ';
					}
				}
			}
			else if (itp == 'textarea')
			{
				var h = '';
				if (a['height'])
				{
					var hh = (a['height'] + ' ').trim();
					if (hh.indexOf('px') < 0 && hh.indexOf('%') < 0)
						hh += 'px';
					h = "style='height:" + hh + "'";
				}
				t += '<textarea ' + (a['objectid'] ? (' id="' + a['objectid'] + '" ') : '') + readonly + ' ' + h + ' class="textarea input form-control ' + classname + '" type="' + itp + '" id="' + name + '" placeholder="' + a['placeholder'] + '"></textarea>';
			}
			else if (itp == 'btnfun')
			{
				t += '<input class="form-control input ' + classname + '" readonly="true" type="text" id="' + name + '" data="' + name + '" placeholder="' + a['placeholder'] + '">';
			}
			else
			{
				app.err('不存在的inputtype：' + itp);
			}
			t += '</div>';
			t += '<div class="col-sm-1">';
			if ((itp == 'btnfun' || a.btnfun) && (!app.vm || !inputbtn))
			{
				t += '<button class="btn btnfun" data="' + name + '">...</button>';
			}
			t += '</div>';
			if (showmemo)
			{
				t += '<div class="col-sm-4 memo">' + a['memo'] + '</div>';
			}
			t += '</div>';
		}
		t += '</div><div class="box-footer">';
		if (this.options.submitTitle !== false)
		{
			if (this.options.submitTitle)
				var sb = this.options.submitTitle;
			else
				var sb = app.w('Submit');
			t += '<button class="btn btn-info pull-right submit">' + sb + '</button>';
		}
		if (this.options.submitOtherBtn)
		{
			for ( var k in this.options.submitOtherBtn)
			{
				if (this.options.submitOtherBtn[k])
					t += '<button style="margin-right:12px" class="btn btn-info pull-right submit submitOtherBtn submitOtherBtn_' + k + '">' + this.options.submitOtherBtn[k]['caption'] + '</button>';
			}
		}
		t += '</div>'
		// 底部文件
		if (this.options.bottomhelphtml)
		{
			t += '<div class="tip bottomhelphtml">' + this.options.bottomhelphtml + '</div>';
		}
		t += '</div>';
		if (container)
		{
			if (container == 'maincontent')
			{
				if (!app.vm)
					t += getIC('close righttopclose', 'span');
				left.setMainContentHtml(t, null, false, '', null, true);
			}
			else
				$('#' + container).html(t);
		}
		var that = this;
		setTimeout(function()
		{
			that.setData();
		}, 100);
		this.html = t;
	}
	/**
	 * 全屏提交框
	 */
	formFun.prototype.showLayer = function(caption, backfun, html, notfull, endfun)
	{
		if (!notfull)
			var curlayerIndex = showFullLayer(caption, this.html + (html ? html : ''), endfun);
		else
			var curlayerIndex = showMsg(caption, this.html + (html ? html : ''), Math.min(600, $(window).width()), endfun, 0, false, true, true);
		var thisbackfun = this.options.requestBackFun;
		if (backfun)
		{
			this.options.requestBackFun = function(d, ad, msg, code)
			{
				if (thisbackfun)
				{
					if (false === thisbackfun(d, ad, msg, code))
						return;
				}
				if (false === backfun(d, ad, msg, code))
					return;
				layer.close(curlayerIndex);
			};
		}
		else
		{
			this.options.requestBackFun = function(d, ad, msg, code)
			{
				if (thisbackfun)
				{
					if (false === thisbackfun(d, ad, msg, code))
						return;
				}
				layer.close(curlayerIndex);
				if (!thisbackfun)
					layer.msg(app.w('optionOk'));
			};
		}
		return curlayerIndex;
	}
	/**
	 * 简易的，根据参数获取值
	 * 
	 * @param para
	 *            [[key,cap,val],[key,cap,val]] val 可以是对象
	 * @returns
	 */
	formFun.prototype.getValues = function(caption, para, backfun, tophtml, options)
	{
		var p = {};
		var h = 0;
		if (para.length > 0)
		{
			for (var i = 0; i < para.length; i++)
			{
				var k = para[i][0];
				p[k] = {
					caption : para[i][1] ? para[i][1] : '',
				};
				var value = para[i][2];
				if (typeof value == 'object')
				{
					for ( var ki in value)
					{
						p[k][ki] = value[ki];
					}
					if (p[k]['inputtype'] === undefined)
						p[k]['inputtype'] = '';
					if (p[k]['value'] === undefined)
						p[k]['value'] = '';
				}
				else
					p[k]['value'] = value || '';
				h += 40;
			}
		}
		else
			p = para;
		var layerIndex = null;
		var pp = {
			'container' : '',
			'showmemo' : false,
			preDealDataFun : function(data)
			{
				if (backfun)
				{
					if (false === backfun(data, layerIndex))
						return null;
				}
				layer.close(layerIndex);
				return null;
			},
			'loadDataFun' : function(backfun)
			{
			},
			'paras' : p
		};
		if (options)
		{
			for ( var k in options)
			{
				pp[k] = options[k];
			}
		}
		var form = new formFun(pp);
		if (!caption)
			caption = app.w('inputValue');
		if (!tophtml)
			tophtml = '';
		var hh = $(window).height();
		if (h < hh - 150)
			h = 'auto';
		else
			h = hh + 'px';
		layerIndex = showList(caption, tophtml + form.html, [ Math.min($(window).width() * 0.9, 480) + 'px', h ]);
		for ( var k in pp.paras)
		{
			setTimeout(function()
			{
				$('#' + form.id + ' input#' + k).focus();
			}, 333);
			break;
		}
	}
	formFun.prototype.getTextFromArray = function(a, pre)
	{
		if (!pre)
			pre = '';
		var tab = "\t";
		var s = '';
		var f = false;
		if (a[0] != undefined || a.length === 0) // 数组
		{
			for (var i = 0; i < a.length; i++)
			{
				if (typeof a[i] == 'object')
					var v = this.getTextFromArray(a[i], pre + tab);
				else
				{
					if (!/^\d+(\.\d+)?$/.test(a[i]) || a[i].length > 8)
						var v = "\"" + (a[i] + ' ').trim().replace(/\"/g, "\\\"") + "\"";
					else
						var v = a[i];
				}
				if (f)
					s += ',';
				s += "\n" + tab + pre + v;
				f = true;
			}
			s = "[" + s + "\n" + pre + "]";
		}
		else
		{
			for ( var k in a)
			{
				if (typeof a[k] == 'object')
					var v = this.getTextFromArray(a[k], pre + tab);
				else
				{
					if (!/^\d+(\.\d+)?$/.test(a[k]) || a[k].length > 8)
						var v = "\"" + (a[k] + ' ').trim().replace(/\"/g, "\\\"") + "\"";
					else
						var v = a[k];
				}
				if (f)
					s += ',';
				s += "\n" + tab + pre + "\"" + k + "\" : " + v;
				f = true;
			}
			s = "{" + s + "\n" + pre + "}";
		}
		return s;
	}
	window.formFun = formFun;
}());
